package com.fwtai.builder;

public final class IdHelper{

  private static IdGenerator idGenInstance = null;

  public static IdGenerator getIdGenInstance() {
    return idGenInstance;
  }

  /**
   * 设置参数，建议程序初始化时执行一次
  */
  public static void setIdGenerator(final IdWorkerOptions options) throws IdWorkerException{
    idGenInstance = new DefaultBuilder(options);
  }

  /**
   * 生成新的Id
   * 调用本方法前，请确保调用了 SetIdGenerator 方法做初始化。
   * @return
  */
  public static long nextId() throws IdWorkerException{
    if (idGenInstance == null)
      throw new IdWorkerException("请先初始化参数");
    return idGenInstance.getKey();
  }
}